package com.yhp.web;

import com.yhp.javabean.Prenum;
import com.yhp.service.impl.PreServiceImpl;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value="/sub")
public class SuccessServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //接受参数
        String count = req.getParameter("count");
        int num = Integer.parseInt(count);
       //点赞数增加
        num++;
        PreServiceImpl psi = new PreServiceImpl();
        psi.updatePre();
       //返回客户端
        Prenum prenum = new Prenum(1,num);
        JSONObject jsonObject = JSONObject.fromObject(prenum);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.print(jsonObject);
    }
}
